//
//  ApiReqGenerator.swift
//  RPay
//
//  Created by CharlieLiao on 2017/7/21.
//  Copyright © 2017年 Charlie. All rights reserved.
//

import UIKit
import AFNetworking

class ApiReqGenerator: NSObject, CTRequestGenerator {
    
    private static let httpRequestSerializer: AFHTTPRequestSerializer = {
        let httpRequestSerializer = AFHTTPRequestSerializer()
        httpRequestSerializer.timeoutInterval = 30
        httpRequestSerializer.cachePolicy = .useProtocolCachePolicy
        return httpRequestSerializer
    }()
    
    public func generateGETRequest(withServiceIdentifier service: CTService, requestParams: [AnyHashable : Any]?, methodName: String) -> URLRequest?
    {
        let urlString = String(format: "%@/%@", service.apiBaseUrl, methodName);
        return ApiReqGenerator.httpRequestSerializer.request(withMethod: "GET", urlString: urlString, parameters: requestParams, error: nil) as URLRequest
    }
    
    public func generatePOSTRequest(withServiceIdentifier service: CTService, requestParams: [AnyHashable : Any]?, methodName: String) -> URLRequest?
    {
        let urlString = String(format: "%@/%@", service.apiBaseUrl, methodName);
        return ApiReqGenerator.httpRequestSerializer.request(withMethod: "POST", urlString: urlString, parameters: requestParams, error: nil) as URLRequest
    }
    
    public func generatePutRequest(withServiceIdentifier service: CTService, requestParams: [AnyHashable : Any]?, methodName: String) -> URLRequest?
    {
        return nil
    }
    
    
    public func generateDeleteRequest(withServiceIdentifier service: CTService, requestParams: [AnyHashable : Any]?, methodName: String) -> URLRequest?
    {
        return nil
    }
}
